function formatTimestampUptoMinute(ts) {
    var dt = new Date(ts * 1000);

    var m = dt.getMonth() >= 9 ? "" + (dt.getMonth() + 1) : "0" + (dt.getMonth() + 1);
    var d = dt.getDate() >= 10 ? "" + dt.getDate() : "0" + dt.getDate();

    var H = dt.getHours() >= 10 ? "" + dt.getHours() : "0" + dt.getHours();
    var M = dt.getMinutes() >= 10 ? "" + dt.getMinutes() : "0" + dt.getMinutes();

    return dt.getFullYear() + '-' + m + '-' + d + ' ' + H + ':' + M;
}

function format_hashrate(hashrate, unit, decimals) {
    if (unit === undefined) unit = 'hash';
    if (decimals === undefined) decimals = 2;
    if (hashrate >= 4e12) {
        return (hashrate / 1e12).toFixed(decimals) + ' T' + unit + '/s';
    } else if (hashrate >= 4e9) {
        return (hashrate / 1e9).toFixed(decimals) + ' G' + unit + '/s';
    } else if (hashrate >= 4e6) {
        return (hashrate / 1e6).toFixed(decimals) + ' M' + unit + '/s';
    } else if (hashrate >= 4e3) {
        return (hashrate / 1e3).toFixed(decimals) + ' K' + unit + '/s';
    } else {
        return (hashrate).toFixed(decimals) + ' ' + unit + '/s';
    }
}

function html_escape(content) {
    var text = document.createTextNode(content);
    var p = document.createElement('p');
    p.appendChild(text);
    return p.innerHTML;
}